/*************************************************************************************** 
Firm-embedded productivity and cross-country income differences
Alviarez, Cravino and Ramondo
Journal of Political Economy (2022)

Program: model_06_additional_robustness.do
Date: October 2022

Description: Constructing the DA dummies (aggregate country effects) such that: 
(a) Controlling for bilateral MNE-specific tax rates 
(b) Controlling for Bilateral Tax Treaties
(c) Controlling for differences in GDP per-worker between source and host country
(d) Excluding gravity variables 
(e) Aggregation at 4-digit NAICS industries 
(f) Excluding Real Estate, Health, and Education 
(g) Excluding MNEs that do not appear in ORBIS every year between 2010-2016
(h) Excluding MNE affiliates incorporated after 2006

*****************************************************************************************/

*-------------------------------------------------------------------------------
global typeden=1
include "set_directories.do"
set memory 64g
global lf "LF"

*Log
cap log close
log using "${clogs}/model_06_additional_robustness.log", replace
*-------------------------------------------------------------------------------



*-------------------------------------------------------------------------------
*Controlling for bilateral MNE-specific tax rates 
*-------------------------------------------------------------------------------
local heading "base_woparent_tax_ratio"  
local timeframe `" "2016" "' 
local varinterest sales 


*Prepare the data for the regressions
*-----------------------------------------------------------
global conditionforage ""
include "${cmain}/prep_01_forreg.do"


if "`heading'"=="base_woparent_tax_ratio" {
*-----------------------------------------------------------
local ending "" 
local zz naics  
local var0 "_`varinterest'" 
local name "_base" 
local name1 "_woparent_tax_ratio" 
local samp=1  
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' 
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE"
global ind_var dist_sec* lang_sec* tax_ratio_sec*
global guoFEonly=0 
global LHS "ln(sin`var0'`denominator')" 
global numctry `" keep if num_ctry>=0 "' 
global pctiles  `" keep if sin_sales>=0 "'  
global other_restr  `" keep if isocode!=hq "' 
global other_restr2  ""
}
*
display "`title'"
local affparent "0" /*"0" is the default, "1" if keeping even one affiliate after parents are dropped*/ 
include "${cmain}/reg_01_naics.do"

*Aggregating the sectoral estimates (Aggregate)
local weightsused_FR=0
local typeused "agg" 
include "${cmain}/reg_02_agg.do"


*Erase intermediate files 
*---------------------------------------------------------
erase "${data}/ctte_naics_sales_s1_base_woparent_tax_ratio.dta"
erase "${data}/firmFE_naics_sales_s1_base_woparent_tax_ratio.dta"
erase "${data}/residual_naics_sales_s1_base_woparent_tax_ratio.dta"
erase "${data}/gravity_naics_sales_s1_base_woparent_tax_ratio.dta"
erase "${data}/reg0_naics_sales_s1_base_woparent_tax_ratio_2016.dta"
erase "${data}/pre_reg0_naics_sales_s1_base_woparent_tax_ratio_2016.dta"




*-------------------------------------------------------------------------------
*Controlling for bilateral tax treaties (BTT) 
*-------------------------------------------------------------------------------
local heading "base_woparent_BTT"  
local timeframe `" "2016" "' 
local varinterest sales 


if "`heading'"=="base_woparent_BTT" {
*-----------------------------------------------------------
local ending "" 
local zz naics  
local var0 "_`varinterest'" 
local name "_base" 
local name1 "_woparent_BTT" 
local samp=1  
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' 
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE"
global ind_var dist_sec* lang_sec* BTT_sec*
global guoFEonly=0 
global LHS "ln(sin`var0'`denominator')" 
global numctry `" keep if num_ctry>=0 "' 
global pctiles  `" keep if sin_sales>=0 "'  
global other_restr  `" keep if isocode!=hq "' 
global other_restr2  ""
}
*
display "`title'"
local affparent "0" /*"0" is the default, "1" if keeping even one affiliate after parents are dropped*/ 
include "${cmain}/reg_01_naics.do"

*Aggregating the sectoral estimates (Aggregate)
local weightsused_FR=0
local typeused "agg" 
include "${cmain}/reg_02_agg.do"


*Erase intermediate files 
*---------------------------------------------------------
erase "${data}/ctte_naics_sales_s1_base_woparent_BTT.dta"
erase "${data}/firmFE_naics_sales_s1_base_woparent_BTT.dta"
erase "${data}/residual_naics_sales_s1_base_woparent_BTT.dta"
erase "${data}/gravity_naics_sales_s1_base_woparent_BTT.dta"
erase "${data}/reg0_naics_sales_s1_base_woparent_BTT_2016.dta"
erase "${data}/pre_reg0_naics_sales_s1_base_woparent_BTT_2016.dta"




*-------------------------------------------------------------------------------
*Controlling for differences in GDP per-worker between source and host country
*-------------------------------------------------------------------------------
local heading "base_woparent_gdpdiff"  
local timeframe `" "2016" "' 
local varinterest sales 


if "`heading'"=="base_woparent_gdpdiff" {
*-----------------------------------------------------------
local ending "" 
local zz naics  
local var0 "_`varinterest'" 
local name "_base" 
local name1 "_woparent_gdpdiff" 
local samp=1  
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' 
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE"
global ind_var dist_sec* lang_sec* gdp_pc_ppp_in
global guoFEonly=0 
global LHS "ln(sin`var0'`denominator')" 
global numctry `" keep if num_ctry>=0 "' 
global pctiles  `" keep if sin_sales>=0 "'  
global other_restr  `" keep if isocode!=hq "' 
global other_restr2  ""
}
*

display "`title'"
local affparent "0" /*"0" is the default, "1" if keeping even one affiliate after parents are dropped*/ 
include "${cmain}/reg_01_naics.do"

*Aggregating the sectoral estimates (Aggregate)
local weightsused_FR=0
local typeused "agg" 
include "${cmain}/reg_02_agg.do"


*Erase intermediate files 
*---------------------------------------------------------
erase "${data}/ctte_naics_sales_s1_base_woparent_gdpdiff.dta"
erase "${data}/firmFE_naics_sales_s1_base_woparent_gdpdiff.dta"
erase "${data}/residual_naics_sales_s1_base_woparent_gdpdiff.dta"
erase "${data}/gravity_naics_sales_s1_base_woparent_gdpdiff.dta"
erase "${data}/reg0_naics_sales_s1_base_woparent_gdpdiff_2016.dta"
erase "${data}/pre_reg0_naics_sales_s1_base_woparent_gdpdiff_2016.dta"




*-------------------------------------------------------------------------------
*Excluding gravity variables 
*-------------------------------------------------------------------------------
local heading "base_woparent_nogravity"  
local timeframe `" "2016" "' 
local varinterest sales 


if "`heading'"=="base_woparent_nogravity" {
*-----------------------------------------------------------
local ending "" 
local zz naics  
local var0 "_`varinterest'" 
local name "_base" 
local name1 "_woparent_nogravity" 
local samp=1  
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' 
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE"
global ind_var dist3_sec* lang3_sec*
global guoFEonly=0 
global LHS "ln(sin`var0'`denominator')" 
global numctry `" keep if num_ctry>=0 "' 
global pctiles  `" keep if sin_sales>=0 "'  
global other_restr  `" keep if isocode!=hq "' 
global other_restr2  ""
}
*

display "`title'"
local affparent "0" /*"0" is the default, "1" if keeping even one affiliate after parents are dropped*/ 
include "${cmain}/reg_01_naics.do"

*Aggregating the sectoral estimates (Aggregate)
local weightsused_FR=0
local typeused "agg" 
include "${cmain}/reg_02_agg.do"


*Erase intermediate files 
*---------------------------------------------------------
erase "${data}/ctte_naics_sales_s1_base_woparent_nogravity.dta"
erase "${data}/firmFE_naics_sales_s1_base_woparent_nogravity.dta"
erase "${data}/residual_naics_sales_s1_base_woparent_nogravity.dta"
erase "${data}/gravity_naics_sales_s1_base_woparent_nogravity.dta"
erase "${data}/reg0_naics_sales_s1_base_woparent_nogravity_2016.dta"
erase "${data}/pre_reg0_naics_sales_s1_base_woparent_nogravity_2016.dta"



*-------------------------------------------------------------------------------
*Aggregation at 4-digit NAICS industries 
*-------------------------------------------------------------------------------
local heading "base_woparent_naics4"  
local timeframe `" "2016" "' 
local varinterest sales 

if "`heading'"=="base_woparent_naics4" {
*-----------------------------------------------------------
local ending "" 
local zz naics4
local var0 "_`varinterest'" 
local name "_base" 
local name1 "_woparent" 
local samp=1  
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' 
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE"
global ind_var dist_sec* lang_sec* 
global guoFEonly=0 
global LHS "ln(sin`var0'`denominator')" 
global numctry `" keep if num_ctry>=0 "' 
global pctiles  `" keep if sin_sales>=0 "'  
global other_restr  `" keep if isocode!=hq "' 
global other_restr2  ""
}
*
display "`title'"
local affparent "0" /*"0" is the default, "1" if keeping even one affiliate after parents are dropped*/ 
include "${cmain}/reg_01_naics.do"

*Aggregating the sectoral estimates (Aggregate)
local weightsused_FR=0
local typeused "agg" 
include "${cmain}/reg_02_agg.do"


*Erase intermediate files 
*---------------------------------------------------------
erase "${data}/ctte_naics4_sales_s1_base_woparent.dta"
erase "${data}/firmFE_naics4_sales_s1_base_woparent.dta"
erase "${data}/residual_naics4_sales_s1_base_woparent.dta"
erase "${data}/gravity_naics4_sales_s1_base_woparent.dta"
erase "${data}/gravitycoef_naics4_sales_s1_base_woparent.dta"
erase "${data}/reg0_naics4_sales_s1_base_woparent_2016.dta"
erase "${data}/pre_reg0_naics4_sales_s1_base_woparent_2016.dta"



*-------------------------------------------------------------------------------
*Excluding Non-Market Economy: Real Estate, Health, and Education 
*-------------------------------------------------------------------------------
local heading "woparent_exclnomark"  
local timeframe `" "2016" "' 
local varinterest sales 


if "`heading'"=="woparent_exclnomark" {
*-----------------------------------------------------------
local ending "" 
local zz naics  
local var0 "_`varinterest'" 
local name "_base" 
local name1 "_woparent_exclnomark" 
local samp=1  
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="Non-Market Economy" "' 
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE"
global ind_var dist_sec* lang_sec* 
global guoFEonly=0 
global LHS "ln(sin`var0'`denominator')" 
global numctry `" keep if num_ctry>=0 "' 
global pctiles  `" keep if sin_sales>=0 "'  
global other_restr  `" keep if isocode!=hq "' 
global other_restr2  ""
}
*
display "`title'"
local affparent "0" /*"0" is the default, "1" if keeping even one affiliate after parents are dropped*/ 
include "${cmain}/reg_01_naics.do"

*Aggregating the sectoral estimates (Aggregate)
local weightsused_FR=0
local typeused "agg" 
include "${cmain}/reg_02_agg.do"


*Erase intermediate files 
*---------------------------------------------------------
erase "${data}/ctte_naics_sales_s1_base_woparent_exclnomark.dta"
erase "${data}/firmFE_naics_sales_s1_base_woparent_exclnomark.dta"
erase "${data}/residual_naics_sales_s1_base_woparent_exclnomark.dta"
erase "${data}/gravity_naics_sales_s1_base_woparent_exclnomark.dta"
erase "${data}/gravitycoef_naics_sales_s1_base_woparent_exclnomark.dta"
erase "${data}/reg0_naics_sales_s1_base_woparent_exclnomark_2016.dta"
erase "${data}/pre_reg0_naics_sales_s1_base_woparent_exclnomark_2016.dta"





*-------------------------------------------------------------------------------
*Excluding MNEs that do not appear in ORBIS every year between 2010-2016
*-------------------------------------------------------------------------------
global cond_ctte `" dummy_ctte==1 "'
include "${cmain}/prep_02_forreg_cttesample.do"

local heading "base_woparent_ctte"  
local timeframe `" "2016" "' 
local varinterest sales 


if "`heading'"=="base_woparent_ctte" {
*-----------------------------------------------------------
local ending "_ctte" 
local zz naics  
local var0 "_`varinterest'" 
local name "_base" 
local name1 "_woparent" 
local samp=1  
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' 
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE"
global ind_var dist_sec* lang_sec* 
global guoFEonly=0 
global LHS "ln(sin`var0'`denominator')" 
global numctry `" keep if num_ctry>=0 "' 
global pctiles  `" keep if sin_sales>=0 "'  
global other_restr  `" keep if isocode!=hq "' 
global other_restr2  ""
}
*
display "`title'"
local affparent "0" /*"0" is the default, "1" if keeping even one affiliate after parents are dropped*/ 
include "${cmain}/reg_01_naics.do"

*Aggregating the sectoral estimates (Aggregate)
local weightsused_FR=0
local typeused "agg" 
include "${cmain}/reg_02_agg.do"


*Erase intermediate files 
*---------------------------------------------------------
erase "${data}/ctte_naics_sales_s1_base_woparent_ctte.dta"
erase "${data}/firmFE_naics_sales_s1_base_woparent_ctte.dta"
erase "${data}/residual_naics_sales_s1_base_woparent_ctte.dta"
erase "${data}/gravity_naics_sales_s1_base_woparent_ctte.dta"
erase "${data}/gravitycoef_naics_sales_s1_base_woparent_ctte.dta"
erase "${data}/reg0_naics_sales_s1_base_woparent_ctte_2016.dta"
erase "${data}/pre_reg0_naics_sales_s1_base_woparent_ctte_2016.dta"




*-------------------------------------------------------------------------------
*Excluding MNE affiliates incorporated after 2006: 
*-------------------------------------------------------------------------------
local heading "base_woparent_aboveage10"  
local timeframe `" "2016" "' 
local varinterest sales 

global conditionforage `" keep if firm_age>=10"'
include "${cmain}/prep_01_forreg.do"


if "`heading'"=="base_woparent_aboveage10" {
*-----------------------------------------------------------
local ending "" 
local zz naics  
local var0 "_`varinterest'" 
local name "_base" 
local name1 "_woparent_aboveage10" 
local samp=1  
local title "`zz'`var0'_s`samp'`name'`name1'`ending'"
display "`title'"

global ctryrel FR
local period "`timeframe'"
global nonmarket `" drop if sector1=="" "' 
global cont_firms `" keep if years_after2010>=0 "'
global cont_firms2 `" keep if years_allperiod>=0 "'
local absFEreg "guoFE"
global ind_var dist_sec* lang_sec* 
global guoFEonly=0 
global LHS "ln(sin`var0'`denominator')" 
global numctry `" keep if num_ctry>=0 "' 
global pctiles  `" keep if sin_sales>=0 "'  
global other_restr  `" keep if isocode!=hq "' 
global other_restr2  ""
}
*
display "`title'"
local affparent "0" /*"0" is the default, "1" if keeping even one affiliate after parents are dropped*/ 
include "${cmain}/reg_01_naics.do"

*Aggregating the sectoral estimates (Aggregate)
local weightsused_FR=0
local typeused "agg" 
include "${cmain}/reg_02_agg.do"


*Erase intermediate files 
*---------------------------------------------------------
erase "${data}/ctte_naics_sales_s1_base_woparent_aboveage10.dta"
erase "${data}/firmFE_naics_sales_s1_base_woparent_aboveage10.dta"
erase "${data}/residual_naics_sales_s1_base_woparent_aboveage10.dta"
erase "${data}/gravity_naics_sales_s1_base_woparent_aboveage10.dta"
erase "${data}/gravitycoef_naics_sales_s1_base_woparent_aboveage10.dta"
erase "${data}/reg0_naics_sales_s1_base_woparent_aboveage10_2016.dta"
erase "${data}/pre_reg0_naics_sales_s1_base_woparent_aboveage10_2016.dta"

 
*Prepare the data for the regressions (go back to the baseline)
*-----------------------------------------------------------
global conditionforage ""
include "${cmain}/prep_01_forreg.do"


log close 

